package com.yhp.servlet;

import com.yhp.service.StudentService;
import com.yhp.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/Educational/student/remove")
public class RemoveServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StudentService studentService = new StudentServiceImpl();
        //接收参数
        String stuid = req.getParameter("stuid");
        int remove = studentService.remove(Integer.parseInt(stuid));
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        if(remove > 0){
            //删除成功
            writer.println("<script>alert('删除成功！');location.href='/Educational/student/getList'</script>");
        }else {
            //删除失败
            writer.println("<script>alert('删除失败！');location.href='/Educational/student/getList'</script>");
        }
    }
}
